var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var BundleConfig = require("AA_BundleConfig");
var ADManager = require("AA_ADManager");
var EventManager = require("AA_EventManager");
var ResLoader = require("AA_ResLoader");
var UIManager = require("AA_UIManager");
var TimeUtils = require("AA_TimeUtils");
var Module_Shop_UIBindings = require("AA_Module_Shop_UIBindings");
var EvenType = require("AA_EvenType");
var Excel = require("AA_Excel");
var HallManager = require("AA_HallManager");
var Item_Shop_BoxItem = require("AA_Item_Shop_BoxItem");
var Item_Shop_GoldItem = require("AA_Item_Shop_GoldItem");
var Item_Shop_TodayItem = require("AA_Item_Shop_TodayItem");
var UIConfig_Home = require("AA_UIConfig_Home");
var BaseModule = require("AA_BaseModule");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_Module_Shop = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.auto_ui = null;
    t.timeStr = "";
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.onLoad = function () {
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.HallResetShopBox, this.ResetBoxLevelAndExp, this);
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.HallScrollShop, this.EventScroll, this);
  };
  _creator.prototype.onDestroy = function () {
    e.prototype.onDestroy.call(this);
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.HallResetShopBox, this.ResetBoxLevelAndExp, this);
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.HallScrollShop, this.EventScroll, this);
  };
  _creator.prototype.show = function (e) {
    this.auto_ui.addClickListener(this._clickListener, this);
    this.StartSet(e);
  };
  _creator.prototype.EventScroll = function (e) {
    if (e) {
      if (e.isUp) {
        this.node.getChildByName("ScrollView_Main").getComponent(cc.ScrollView).scrollToTop(.2);
      } else {
        e.isBottom && this.node.getChildByName("ScrollView_Main").getComponent(cc.ScrollView).scrollToBottom(.2);
      }
    }
  };
  _creator.prototype.hide = function () { };
  _creator.prototype.StartSet = function (e) {
    var t = this;
    undefined === e && (e = null);
    var o = Excel.Excel.shopControl(1);
    var n = this.auto_ui;
    var i = HallManager.HallMgr.CheckNextResetTime();
    this.ShowTimeLabel(i);
    this.auto_ui.btn_ResetTodayBtn.interactable = o.lastResetCount - HallManager.HallMgr.shopData.todayResetCount > 0;
    var a = i;
    n.txt_todayResetTimeLabel.node.stopAllActions();
    n.txt_todayResetTimeLabel.node.runAction(cc.repeat(cc.sequence(cc.delayTime(1), cc.callFunc(function () {
      i--;
      t.ShowTimeLabel(i);
      i < 0 && t.StartSet();
    })), a));
    n.txt_todayLastCountLabel.string = "" + (o.lastResetCount - HallManager.HallMgr.shopData.todayResetCount);
    this.ResetBoxLevelAndExp();
    this.ShowTodayItem().then(function () {
      t.ShowBoxItem().then(function () {
        t.ShowGoldItem().then(function () {
          e && t.scheduleOnce(function () {
            t.EventScroll(e);
          });
        });
      });
    });
  };
  _creator.prototype.ShowTodayItem = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      var o;
      return __generator(this, function (n) {
        switch (n.label) {
          case 0:
            if (0 != (e = this.auto_ui.node_todayFather).childrenCount) {
              return [3, 2];
            } else {
              return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Home, "home/item/item_shop_todayItem", cc.Prefab)];
            }
          case 1:
            t = n.sent();
            for (o = 0; o < 6; o++) {
              e.addChild(cc.instantiate(t));
            }
            n.label = 2;
          case 2:
            for (o = 0; o < e.children.length; o++) {
              e.children[o].getComponent(Item_Shop_TodayItem.default).StartSet(o);
            }
            return [2];
        }
      });
    });
  };
  _creator.prototype.ShowBoxItem = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      var o;
      return __generator(this, function (n) {
        switch (n.label) {
          case 0:
            if (0 != (e = this.auto_ui.node_boxFather).childrenCount) {
              return [3, 2];
            } else {
              return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Home, "home/item/item_shop_boxItem", cc.Prefab)];
            }
          case 1:
            t = n.sent();
            for (o = 0; o < 2; o++) {
              e.addChild(cc.instantiate(t));
            }
            n.label = 2;
          case 2:
            for (o = 0; o < e.children.length; o++) {
              e.children[o].getComponent(Item_Shop_BoxItem.default).StartSet(o, this.auto_ui.txt_todayResetTimeLabel);
            }
            return [2];
        }
      });
    });
  };
  _creator.prototype.ShowGoldItem = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      var o;
      return __generator(this, function (n) {
        switch (n.label) {
          case 0:
            if (0 != (e = this.auto_ui.node_goldFather).childrenCount) {
              return [3, 2];
            } else {
              return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Home, "home/item/item_shop_goldItem", cc.Prefab)];
            }
          case 1:
            t = n.sent();
            for (o = 0; o < 3; o++) {
              e.addChild(cc.instantiate(t));
            }
            n.label = 2;
          case 2:
            for (o = 0; o < e.children.length; o++) {
              e.children[o].getComponent(Item_Shop_GoldItem.default).StartSet(o);
            }
            return [2];
        }
      });
    });
  };
  _creator.prototype.ShowTimeLabel = function (e) {
    this.timeStr = TimeUtils.default.secondsToHMS(e);
    this.auto_ui.txt_todayResetTimeLabel.string = this.timeStr;
  };
  _creator.prototype._clickListener = function (e) {
    switch (e) {
      case this.auto_ui.btn_ResetTodayBtn:
        this.ResetTodayShop();
        break;
      case this.auto_ui.btn_boxExpInfoBtn:
        UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_BoxLevelInfo);
    }
  };
  _creator.prototype.ResetTodayShop = function () {
    var e = this;
    var t = Excel.Excel.shopControl(1);
    if (t.lastResetCount - HallManager.HallMgr.shopData.todayResetCount != 0) {
      ADManager.ADMgr.showRewardedVideo("商城视频刷新每日商店", function () {
        HallManager.HallMgr.shopData.todayResetCount++;
        HallManager.HallMgr.ResetTodayShop();
        e.ShowTodayItem();
        var o = t.lastResetCount - HallManager.HallMgr.shopData.todayResetCount;
        e.auto_ui.txt_todayLastCountLabel.string = "" + o;
        o <= 0 && (e.auto_ui.btn_ResetTodayBtn.interactable = false);
      });
    } else {
      this.auto_ui.btn_ResetTodayBtn.interactable = false;
    }
  };
  _creator.prototype.ResetBoxLevelAndExp = function () {
    var e = Excel.Excel.shopBoxLevel(HallManager.HallMgr.shopData.boxLevel + 1);
    if (HallManager.HallMgr.shopData.boxExp >= e.exp && e.exp > 0) {
      HallManager.HallMgr.shopData.boxLevel++;
      HallManager.HallMgr.shopData.boxExp -= e.exp;
      e = Excel.Excel.shopBoxLevel(HallManager.HallMgr.shopData.boxLevel + 1);
    }
    this.auto_ui.txt_boxLevelLabel.string = "LV." + (HallManager.HallMgr.shopData.boxLevel + 1);
    if (e && e.exp) {
      this.auto_ui.txt_boxExpLabel.string = HallManager.HallMgr.shopData.boxExp + "/" + e.exp;
      this.auto_ui.progress_boxExpBar.progress = HallManager.HallMgr.shopData.boxExp / e.exp;
    } else {
      this.auto_ui.txt_boxExpLabel.string = "MAX";
      this.auto_ui.progress_boxExpBar.progress = 1;
    }
  };
  __decorate([_property(Module_Shop_UIBindings.default)], _creator.prototype, "auto_ui", undefined);
  return __decorate([_ccclass], _creator);
}(BaseModule.default);
exports.default = _def_Module_Shop;